Print a dictionary in table formatΒΆ
Print a dictionary in table format.
def print_in_table_format(D):
for row in zip(*([key] + (value) for key, value in sorted(D.items()))):
print(*row)
def print_in_table_format_01(D):
print(*D.keys())
for i in range(len(D[list(D.keys())[0]])):
print( *[str(x[i]) for x in D.values()] )
Test:
DOL = {'C1': [1, 2, 3],
'C2': [5, 6, 7],
'C3': [9, 10, 11],
}
print(print_in_table_format(DOL))
print()
print(print_in_table_format_01(DOL))
Output:
C1 C2 C3
1 5 9
2 6 10
3 7 11
None